<?php 
include_once 'inc.php' ;
date_default_timezone_set("Asia/Shanghai");

if( $_GET['show'] == "author" ){
	header('content-Type: image/png', true);
	die(base64_decode(myinfo()));
}
if( $_POST['action'] == "make" ){


	if(!isset($_COOKIE['card_user'])){
			setcookie("card_user", $_SERVER['REMOTE_ADDR'] , time()+60*60*24);
			setcookie("card_user_time", 1 , time()+60*60*24);
			$isMax = false;
	}else{
			if( $_COOKIE["card_user"] == $_SERVER['REMOTE_ADDR'] ){
				if( $_COOKIE['card_user_time'] > $config['max'] ){
					$isMax = true;
				}else{
					setcookie("card_user_time", $_COOKIE['card_user_time']+1 , time()+60*60*24);	
					$isMax = false;	
				}
			}else{
				setcookie("card_user", $_SERVER['REMOTE_ADDR'] , time()+60*60*24);
				setcookie("card_user_time", 1 , time()+60*60*24);
				$isMax = false;
			}
	}
	if(!$isMax){
		getSN();
	}else{
		echo '{"info":"none","no":"-1988"}';
	}
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $config['site_name'] ;?> - Powered by mrasong.com</title>
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<div class="index_show">
    <div id="step_1">
    	<h3><?php echo $config['str_0'] ;?></h3>
    	<h2><span class="h">5</span> <?php echo $config['str_1'] ;?></h2>
        <h3><?php echo $config['str_2'] ;?></h3>
    </div>
    <div id="step_2">
    	<h3>&nbsp;  </h3>
    	<h3><?php echo $config['str_3'] ;?></h3>
        <p><input type="button" id="confirm" value="<?php echo $config['str_4'] ;?>" /></p>
    </div>
    <div id="step_3">
    	<h3><?php echo $config['str_5'] ;?></h3>
    	<p> <span><input type="text" class="text" id="showsn" value="" /></span>
        <input type="button"  class="btn"  id="copySN"  value="<?php echo $config['str_6'] ;?>" />
        </p>
        <p> <span><input type="text" class="text"  id="showurl" value="<?php echo $config['site_url'] ;?>" /></span>
        <input type="button"  class="btn"  id="copyURL"  value="<?php echo $config['str_8'] ;?>" /></p>
    	<p><?php //echo $config['str_7'] ;?> <input type="button" class="btn" id="refresh" value="<?php echo $config['str_14'] ;?>" /></p>
    </div>
    <div id="notice"></div>
    <div id="showtips"></div>
</div>
</body>
<script type="text/javascript">
n = <?php echo $config['str_sec'] ;?>; 
function count(){
	$(".h").html(n--);
	if( n >= 0 ){
		setTimeout("count()",1000);
	}else{
		n = <?php echo $config['str_sec'] ;?>;
		$("#step_1").slideUp(500);
		$("#step_2").slideDown(500);
	}
}

function copy_code(copyText){
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text", copyText)
	} 
	else 
	{
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) 
		{
		  var divholder = document.createElement('div');
		  divholder.id = flashcopier;
		  document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
  $("#notice").html("<?php echo $config['str_9'] ;?>");
  $("#notice").slideDown(500);
  setTimeout(function(){ $("#notice").slideUp(500);},2000);
}
$(document).ready(function(){
	count();
	$("#confirm").click(function(){
		$("#confirm").attr("disabled","disabled");
		$("#confirm").val("<?php echo $config['str_13'] ; ?>");
		$.ajax({
			url: "index.php",
			type: "POST",
			data: "action=make&time=" + new Date().getTime(),
			dataType: "json",
			success: function(d){
				if( d.no == '-1988' ){
					$("#showtips").html("<?php echo $config['str_10'].$config['time'].$config['str_10_1']." ".$config['max']." ".$config['str_11'] ;?>").slideDown(500);
					$("#showtips").slideDown(500);
					setTimeout(function(){ $("#showtips").slideUp(500) },3000);
				}else if( d.no == "0" ){
					$("#showtips").html("<?php echo $config['str_12'];?>");
					$("#showtips").slideDown(500);
					setTimeout(function(){ $("#showtips").slideUp(500) },3000);	
				}else{
					$("#showsn").val( d.sn );
					$("#step_2").slideUp(500);
					$("#step_3").slideDown(500);
				}
				$("#confirm").val('<?php echo $config['str_4'] ; ?>');
				$("#confirm").removeAttr("disabled");
			}			
		});	
	});	
	$("#refresh").click(function(){
		window.location.reload();
	});
	$("#copySN").click(function(){
		copy_code($("#showsn").val());
	});
	$("#copyURL").click(function(){
		copy_code($("#showurl").val());
	});
});
</script>
</html>
<?php } ?>